package com.shanzmoo.platform.manage.api.manager.product;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.util.CollectionUtil;
import com.shanzmoo.db.module.product.domain.dto.ScoreModeSaveDto;
import com.shanzmoo.db.module.product.domain.vo.ScoreModeVO;
import com.shanzmoo.db.module.product.entity.ProductScoreModeEntity;
import com.shanzmoo.db.module.product.service.IProductScoreModeService;
import com.shanzmoo.platform.manage.api.util.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 积分商品类型manager
 * @author xueqz
 */
@Component
public class ProductScoreModeManager {

    @Autowired
    private IProductScoreModeService productScoreModeService;


    public SHttpResponse<List<ScoreModeVO>> getScoreModeList() {
        List<ProductScoreModeEntity> list = productScoreModeService.list(new QueryWrapper<ProductScoreModeEntity>().eq("deleted", Boolean.FALSE));
        List<ScoreModeVO> rs = CollectionUtil.convert(list, ScoreModeVO.class);
        return SHttpResponse.ok(rs);
    }

    public SHttpResponse<Integer> addScoreMode(ScoreModeSaveDto scoreModeSaveDto) {
        ProductScoreModeEntity convert = scoreModeSaveDto.convert(ProductScoreModeEntity.class);
        convert.setCreateUser(SecurityUtil.getCurrentUserId());
        Assert.isTrue(StrUtil.isNotBlank(convert.getName()),"创建商品单位品牌失败");
        productScoreModeService.save(convert);
        return SHttpResponse.ok(convert.getId());
    }
}
